import { login } from '@/api/user'
const state = {
  token: localStorage.getItem('token') || ''
}

const mutations = {
  setToken(state, payload) {
    localStorage.setItem('token', payload)
    state.token = payload
  }
}

const actions = {
  async login(context, payload) {
    const res = await login(payload)
    console.log('vuex 登录逻辑', res)
    context.commit('setToken', res.jwt)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
